package pers.cnzdy.tutorial.Chapter5_UI.Section7_ListView;

import android.util.Log;

import java.util.ArrayList;
import java.util.List;

import pers.cnzdy.tutorial.BuildConfig;
import pers.cnzdy.tutorial.R;

public class KnowledgePoints {
    public static String TAG = "KnowledgePoints";

    private List<KnowledgePoint> knowledgePointList = new ArrayList<KnowledgePoint>();

    public KnowledgePoints()
    {
        initKnowledgePoints();
    }

    public List<KnowledgePoint> getKnowledgePointList() {
        return knowledgePointList;
    }

    private void initKnowledgePoints() {
        if(BuildConfig.DEBUG && knowledgePointList == null){
            Log.d(TAG, "initKnowledgePoints: knowledgePointList == null");
        }

        KnowledgePoint fragment   =
                new KnowledgePoint("Fragment", R.drawable.ic_fragment);
        KnowledgePoint activity   =
                new KnowledgePoint("Activity", R.drawable.ic_activity);
        KnowledgePoint intent     =
                new KnowledgePoint("Intent", R.drawable.ic_intent);
        KnowledgePoint service    =
                new KnowledgePoint("Service", R.drawable.ic_service);
        KnowledgePoint broadcast  =
                new KnowledgePoint("BroadcastReceiver", R.drawable.ic_broadcase);
        KnowledgePoint database   =
                new KnowledgePoint("SQLite", R.drawable.ic_database);
        KnowledgePoint resource   =
                new KnowledgePoint("Resource", R.drawable.ic_resource);

        fragment.setDetail("在 Android 系统中代表用户界面的局部区域，" +
                "它可以是一个活动的部分，可以单独设置局部用户界面，" +
                "也可以单独接收用户输入和处理事件消息，与用户交互。");

        knowledgePointList.add(activity);
        knowledgePointList.add(fragment);
        knowledgePointList.add(intent);
        knowledgePointList.add(broadcast);
        knowledgePointList.add(resource);
        knowledgePointList.add(database);
        knowledgePointList.add(service);

        if(BuildConfig.DEBUG && knowledgePointList.size() != 7){
            Log.d(TAG, "initKnowledgePoints: knowledgePointList.size() != 7" );
        }
    }

    public class KnowledgePoint {
        String caption;
        int    imageID;      // 在ListView中显示的图片ID号
        String detail;

        public KnowledgePoint(String caption, int imageID) {
            this.caption = caption;
            this.imageID = imageID;
        }

        public int getImageID() {
            return imageID;
        }

        public String getCaption() {
            return caption;
        }

        public String getDetail() {
            return detail;
        }

        public void setDetail(String detail) {
            this.detail = detail;
        }
    }
}
